<?php
/**
 * Notes:
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/10/4
 * Time: 13:14
 */

namespace app\model;


use think\Model;

class GroupChatList extends Model
{
    public function getGroupChatUserList($group_chat_id){
        return self::where([
            'group_chat_id' => $group_chat_id
        ])->select();
    }
    public function add($data){
        return self::create($data);
    }
    public function del($group_chat_list_id){
        return self::get(group_chat_list_id)->delete();
    }
    public function disGroupChat($group_chat_id){
        return self::where(['group_chat_id' => $group_chat_id]) -> delete();
    }
    public function edit($group_chat_list_id,$data){
        return self::allowField(true)->save($data,['group_chat_list_id' => $group_chat_list_id]);
    }
    public function check($group_chat_list_id){
        return self::get($group_chat_list_id)->count();
    }

    public function getChatListByUser($user_id){
        return self::where(['user_id' => $user_id])->select();
    }

    public function groupchat(){
        return $this->hasOne('GroupChat','group_chat_id','group_chat_id');
    }

    public function getUserChatList($user_id){
        return self::with('GroupChat')->where(['user_id' => $user_id])->select();
    }

    public function checkByUser($user_id,$group_chat_id){
        return self::where([
            'user_id' => $user_id,
            'group_chat_id' => $group_chat_id
        ])->count();
    }
    public function moveUser($user_id,$group_chat_id){
        return self::where([
            'user_id' => $user_id,
            'group_chat_id' => $group_chat_id
        ])->delete();
    }
    public function checkLevel($level){
        if($level > 10){
            return true;
        }
        return false;
    }
    public function getStatus($value){
        $status = [ 1 => '正常', 2 => '禁言'];
    }

}